Image mapping using lookup tables [on hold]

Posted by jblasius on Programmers See other posts from Programmers or by jblasius
Published on 2013-10-22T17:12:49Z Indexed on 2013/10/23 10:15 UTC
Read the original article Hit count: 186

Filed under:
|

I have an optimization problem.

I'm using a look-up table to map a pixel in an image:

for (uint32_t index = 0u; index < imgSize; index++)
{
    img[ lt[ index ] ] = val;
}

Is there a faster way to do this, perhaps using a reinterpret_cast or something like that?

I am accessing two different memory addresses, so what is the compiler doing?

One solution is to do a set of reads to access adjacent memory addresses.

struct mblock
{
    uint32_t buf[10u];
};
mblock mb;
for (uint32_t index = 0u; index < imgSize; index += 10u)
{
     mb = *reinterpret_cast<mblock*>(lt + index));
     for (uint8_t i = 0u; i < 10u; i ++)
     {
          mb.buf[i] += img;
     }
     for (uint8_t i = 0u; i < 10u; i ++)
     {
          *( mb.buf[i] ) = val;
     }
}

This speeds up the code because I'm separating the image access from the table look-up; the positions in the look-up table are adjacent.

I still get the image access problem as it is accessing random address positions.

© Programmers or respective owner

Related posts about c++

Related posts about image